import { defineStore } from "pinia";
import { getPortfoliosList, addViews } from "../api/modules/api.portfolios";
export const useProjectStore = defineStore('project', () => {

    const getProjectListPinia = async () => {
        try {
            const res = await getPortfoliosList();
            if (res.status === 200) {
                // 直接返回数据库中的项目数据
                return {success:true,data:res.data.projects}
            }else{
                return {success:false,data:res.data.message||'获取项目列表失败'}
            }
        } catch (error) {
            // console.log(error);
            return {success:false,data:error.message||'获取项目列表失败'}
        }
    }

    const addProjectViews = async (id) => {
        try {
            const res = await addViews({ id });
            if (res.status === 200) {
                return { success: true, message: res.data.data.message };
            } else {
                return { success: false, message: res.data.data.message || '增加浏览量失败' };
            }
        } catch (error) {
            // console.log(error);
            return { success: false, message: error.message || '增加浏览量失败' };
        }
    }

    return {
        getProjectListPinia,
        addProjectViews
    }
})